#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020-12-08 10:03 上午
# @Author  : yangdy
# @File    : 2020-12-08.2.1679.K和数对的最大数目
# @Software: PyCharmCE
from tools.my_methods import *


class Solution:
    def maxOperations(self, nums: List[int], k: int) -> int:
        m, ans = {}, 0
        for x in nums:
            if m.get(k-x):
                m[k-x] -= 1
                ans += 1
            else:
                if m.get(x):
                    m[x] += 1
                else:
                    m[x] = 1
        return ans


questions = [
    ([1, 2, 3, 4], 5),
    ([3, 1, 3, 4, 3], 6),
]

work(questions, lambda q: Solution().maxOperations(q[0], q[1]))


